package com.wjpeng.wms.util;

import com.wjpeng.wms.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.lang.reflect.Method;
import java.util.List;

//
public class UserContext {

    public static final String EMP_IN_SESSION = "EMP_IN_SESSION";//用户登陆session
    public static final String EXP_IN_SESSION = "EXP_IN_SESSION";//权限表达式session


    //获取session对象
    private static HttpSession getSession(){
        return ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes()))
                .getRequest().getSession();
    }


    //把登陆成功的用户存入一个session中
    public static void  setCurrentUser(Employee employee){
        getSession().setAttribute(EMP_IN_SESSION,employee);

    }

    public static Employee  getCurrentUser(){
        return (Employee) getSession().getAttribute(EMP_IN_SESSION);
    }


    //把所有的权限表达式expressions存入到一个session中
    public static void  setExpression(List<String> expressions){
        getSession().setAttribute(EXP_IN_SESSION,expressions);

    }

    public static List<String>  getExpression(){
        return (List<String>) getSession().getAttribute(EXP_IN_SESSION);
    }

}
